/*
 * Copyright (C) 2017-2019 Alibaba Group Holding Limited
 */
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include "aos/hal/pcm.h"

__attribute__((weak)) int aos_audio_pcm_init(void)
{
    return 0;
}

/**
 * Open pcm device
 *
 * Return:
 *   0 -- success
 *  -1 -- failed
 */
__attribute__((weak)) int aos_audio_pcm_open(aos_audio_pcm_device_t *pcm)
{
    if (pcm == NULL) {
        return -1;
    }
    // ??pcm????????/pwm??
    // DMA buffer size = period_size * period_count
    // rate means audio sample, eg: 8K hz
    // channels means which pwm channles use for pwm audio
    // period_size means ??DMA???????,???period(setup???????)
    // period_count means DMA buffer????period?

    return 0;
}

/*
 * Block write if free dma buffer not ready, otherwise,
 * please return after copied.
 *
 * Return writen length, or negative if failed.
 *
 */
__attribute__((weak)) int aos_audio_pcm_write(aos_audio_pcm_device_t *pcm, unsigned char *buffer, int nbytes)
{
    if (pcm == NULL || buffer == NULL) {
        return -1;
    }

    //??????(?????),??,??????
    return 0;
}

/*
 * close pcm device
 *
 * Return:
 *   0 -- success
 *  -1 -- failed
 *
 */
__attribute__((weak)) int aos_audio_pcm_close(aos_audio_pcm_device_t *pcm)
{
    if (pcm == NULL) {
        return -1;
    }
    return 0;
}

